<?php
	class hangsanxuat{
		public $id;
		public $TenHang;
		public $TrangThai;
		public function getAllHangSanXuatByWhere($where,$order){
			
			$db = new db();
			$db->getInstance();
			$sql = "select * from tblhangsanxuat";
			if($where != '') $sql .= ' where ' . $where;
			if($order != '') $sql .= ' order by ' . $order; //echo $sql; die;
			$rs = mysql_query($sql);
			while($rc = mysql_fetch_object($rs)){
				$lstHangSanXuat[] = $rc;	
			}
			return $lstHangSanXuat;
		}
		
		public function getHangSanXuatById($id){
			$db = new db();
			$db->getInstance();
			$sql = "Select * from tblhangsanxuat where id = " . $id;
			$rs = mysql_query($sql);
			$rc = mysql_fetch_object($rs);
			return $rc;
		}
		
		public function getHangsanxuatByWherePaging($where, $order, $pos){
			
			$db = new db();
			$db->getInstance();
			$sql = "select * from tblhangsanxuat ";
			if($where != '') $sql .= ' where ' . $where; 
			if($order != '') $sql .= ' order by ' . $order;
			$sql .= ' limit '.$pos.','.__PAGE_SIZE; //echo $sql;die;
			$rs = mysql_query($sql);
			if(mysql_num_rows($rs) > 0){
				while($rc = mysql_fetch_object($rs)){
					$lstTivi[] = $rc;	
				}
				return $lstTivi;
			}
			else
				return null;
		}
		
		public function insert($hang){
			$db = new db();
			$db->getInstance();
			$sql = "Insert tblhangsanxuat(TenHang,TrangThai) values('".$hang->TenHang."',".$hang->TrangThai.")"; //echo $sql; die;
			$rs = mysql_query($sql);
			if($rs) return true;
			else return false;
		}
		
		public function update($hang){
			$db = new db();
			$db->getInstance();
			$sql = "Update tblhangsanxuat set TenHang='".$hang->TenHang."',TrangThai=".$hang->TrangThai." where id =".$hang->id; //echo $sql; die;
			$rs = mysql_query($sql);
			if($rs) return true;
			else return false;
		}
		
		public function delete($id){
			$db = new db();
			$db->getInstance();
			$sql = "delete from tblhangsanxuat where id=".$id; //echo $sql; die;
			$rs = mysql_query($sql);
			if($rs) return true;
			else return false;
		}
	}
?>